home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Imágenes y mapas de bits / HelloWorldBitmap / HelloWorldBitmap.cs next >
Encoding:
Text File  |  2002-05-06  |  1.2 KB  |  41 lines

  1. //-----------------------------------------------
  2. // HelloWorldBitmap.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class HelloWorldBitmap: PrintableForm
  9. {
  10.      const  float fResolution = 300;
  11.      Bitmap bitmap;
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new HelloWorldBitmap());
  16.      }
  17.      public HelloWorldBitmap()
  18.      {
  19.           Text = "íHola mundo!";
  20.  
  21.           bitmap = new Bitmap(1, 1);
  22.           bitmap.SetResolution(fResolution, fResolution);
  23.  
  24.           Graphics grfx = Graphics.FromImage(bitmap);
  25.           Font     font = new Font("Times New Roman", 72);
  26.           Size     size = grfx.MeasureString(Text, font).ToSize();
  27.  
  28.           bitmap = new Bitmap(bitmap, size);
  29.           bitmap.SetResolution(fResolution, fResolution);
  30.                
  31.           grfx = Graphics.FromImage(bitmap);
  32.           grfx.Clear(Color.White);
  33.           grfx.DrawString(Text, font, Brushes.Black, 0, 0);
  34.           grfx.Dispose();
  35.      }
  36.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  37.      {
  38.           grfx.DrawImage(bitmap, 0, 0);
  39.      }
  40. }
  41.